# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
using("SideMenu_Open.air")
import SideMenu_Open
        
class SideMenu_Annoucement(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        # 打开左侧菜单
        isOpenSideMenu = SideMenu_Open.runTest({})
        if not isOpenSideMenu:
            return False

        # 获取左侧菜单节点
        bottomPanel = poco("bottom_panel")
        if not bottomPanel.exists():
            return False

        btnAnnoucement = bottomPanel.offspring("ntf_btn")
        if not btnAnnoucement.exists():
            return False

        self.clickButton(btnAnnoucement)

        try:
            poco("ActiveNoticeView").wait_for_appearance()
        except:
            assert(True, True, "公告面板正常弹出")
            return False

        annoucementLayer = poco("ActiveNoticeView")

        noticeList = annoucementLayer.offspring("listview_notice")
        if not noticeList.exists():
            assert(True, True, "公告列表不为空")
            return False

        items = noticeList.offspring("panel_notice_item")

        # 如果有1个以上的公告，则切换一下公告
        if len(items) > 1:
            self.clickButton(items[1])

        # 切换至活动页
        btnChangeTab = annoucementLayer.offspring("image_tab_1")
        self.clickButton(btnChangeTab)

        btnClose = annoucementLayer.offspring("button_back")
        if btnClose.exists():
            self.clickButton(btnClose)

        poco.click([0.7, 0.5])
        return True
        
_instance = SideMenu_Annoucement()
runTest = _instance.runTest